﻿using System;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

namespace TheWorldOfKongfuEasyMod;

[HarmonyPatch(typeof(StatusSub4))]
[HarmonyPatch("OnButtonClick")]
public static class Patch_StatusSub4_OnButtonClick
{
    static bool Prefix(ref StatusSub4 __instance, CharaData ___curdata, GameObject go)
    {
        if ((UnityEngine.Object)go == (UnityEngine.Object)null ||
            !go.activeInHierarchy ||
            (UnityEngine.Object)go.GetComponent<Button>() == (UnityEngine.Object)null ||
            !go.GetComponent<Button>().IsInteractable())
            return false;
        var mPackageController = SharedData.Instance(false).m_PackageController;
        var equipBtnData = mPackageController.gameObject.GetComponent<EquipBtnData>();
        if (!equipBtnData)
        {
            equipBtnData = mPackageController.gameObject.AddComponent<EquipBtnData>();
        }
        string[] strArray = go.name.Split('|', StringSplitOptions.None);
        if (!(strArray[0] == "Equip"))
            return false;
        int num = int.Parse(strArray[1]);
        string _topFilter = "11111111111";
        switch (num)
        {
            case 0:
                _topFilter = "00100000000";
                break;
            case 1:
                _topFilter = "00010000000";
                break;
            case 2:
                _topFilter = "00001000000";
                break;
        }

        CommonResourcesData.inputDeviceDetector.PushJoyStack();

        equipBtnData.currentSlotName = ___curdata.m_EquipSlot[num];
        mPackageController.OpenPackage(_packagerFunction: PackagerFunction.Equip, _topFilter: _topFilter);
        return false;
    }
}